package com.otherTest.sort;

import org.junit.Test;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Random;

/**
 * 测试sort 效率
 *
 * @author Conceit
 * 2018/2/9 增加方法
 * @since 1.0.0, 2018/2/9
 */
public class TestSortPerformance {

    @Test
    public  static int[] getRandomInts(int length){
        //生成一个length长的int Array
        int ints[] = new int[length];
        int max=Integer.MAX_VALUE;
        int min=Integer.MIN_VALUE;

        for(int i=0;i<length;i++){
            //int randNumber =rand.nextInt(MAX - MIN + 1) + MIN; // randNumber 将被赋值为一个 MIN 和 MAX 范围内的随机数
            ints[i]=new Random().nextInt(max) + 1;
//            System.out.println(ints[i]);
        }

        return ints;
    }

    @Test
    public static void main(String[] args) {

        BubbleSort bubbleSort=new BubbleSort();
        FastSort fastSort=new FastSort();

        LocalDateTime beforeLocalDateTime = LocalDateTime.now();
        System.out.println("调用前时间为--->"+beforeLocalDateTime);

//        int [] ints=bubbleSort.bubbleSort5(TestSortPerformance.getRandomInts(100000));
          fastSort.fastsort(TestSortPerformance.getRandomInts(10000));
//        for(int j=0;j<ints.length;j++){
//            System.out.println(ints[j]);
//        }
//        for(int i:ints){
//            System.out.println(i);
//        }
        LocalDateTime afterLocalDateTime = LocalDateTime.now();
        System.out.println("调用后时间为--->"+afterLocalDateTime);

        //共历时
        System.out.println(Duration.between(beforeLocalDateTime,afterLocalDateTime));

    }

    @Test
    public void test1(){
        int max=Integer.MAX_VALUE-1;

        int min=Integer.MIN_VALUE+1;
        System.out.println(max);
        System.out.println(min);

        for(int i=0;i<100;i++){
            System.out.println(new Random().nextInt(max));
        }


    }
}
